package com.helloae.chap06;

import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;

import com.esri.arcgis.geodatabase.FeatureClassName;
import com.esri.arcgis.geodatabase.FeatureDataConverter;
import com.esri.arcgis.geodatabase.WorkspaceName;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.system.esriLicenseProductCode;
/**
 * Coverage转换成Shapefile并存储。<br>
 * 改程序没有对重复文件进行检测，因此如果输出文件已存在，那么将提示错误<br>
 * 请注意这里与CoverageToAccess不同的是输出参数的配置使用了PropertySet，很明显这个东西比较复杂，并不如直接给属性赋值容易
 * 示例章节：6.4.2
 * @author zhushijie
 *
 */
public class Coverage2Shape {

	public static void main(String[] args) throws UnknownHostException, IOException {
		EngineInitializer.initializeEngine();
		AoInitialize ao = new AoInitialize();
		ao.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
		
		//读取输入文件
		String ecliseWorkspace = System.getenv("Eclipse3.6Workspace");
		WorkspaceName pInCovWorkspaceName = new WorkspaceName();
		pInCovWorkspaceName.setPathName(ecliseWorkspace+"HelloAE"+File.separator+"DataSet"+File.separator+"chap06");
		pInCovWorkspaceName.setWorkspaceFactoryProgID("esriDataSourcesFile.ArcInfoWorkspaceFactory");
		FeatureClassName pInFCName = new FeatureClassName();
		pInFCName.setName("breakstrm:arc");
		pInFCName.setWorkspaceNameByRef(pInCovWorkspaceName);
		
		//设置输出文件路径及输出文件格式
		PropertySet pPropset = new PropertySet();
		pPropset.setProperty("DATABASE", ecliseWorkspace+"HelloAE"+File.separator+"DataSet"+File.separator+"chap06");
		WorkspaceName pOutShWSName = new WorkspaceName();
		pOutShWSName.setConnectionProperties(pPropset);
		pOutShWSName.setWorkspaceFactoryProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
		
		//设置输出文件名
		FeatureClassName pOutShFCName = new FeatureClassName();
		pOutShFCName.setWorkspaceNameByRef(pOutShWSName);
		pOutShFCName.setName("breakstrm.shp");
		
		//转换
		FeatureDataConverter pCovtoshape = new FeatureDataConverter();
		pCovtoshape.convertFeatureClass(pInFCName, null, null, pOutShFCName, null, null, "", 1000, 0);
		
		ao.shutdown();
		System.out.println("Congratulations!");
	}

}
